﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract EstadoPedidos typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class EstadoPedidosDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<EstadoPedidosDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.EstadoPedidos _currentEstadoPedidos = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxEstadoPedidosDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxEstadoPedidosErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxEstadoPedidosBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IdEstadoPedido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdEstadoPedidoDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the EstadoPedido property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxEstadoPedidoDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.EstadoPedidos> _EstadoPedidosList;
				
		/// <summary> 
		/// The list of EstadoPedidos to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.EstadoPedidos> EstadoPedidosList
		{
			get {return this._EstadoPedidosList;}
			set
			{
				this._EstadoPedidosList = value;
				this.uxEstadoPedidosBindingSource.DataSource = null;
				this.uxEstadoPedidosBindingSource.DataSource = value;
				this.uxEstadoPedidosDataGridView.DataSource = null;
				this.uxEstadoPedidosDataGridView.DataSource = this.uxEstadoPedidosBindingSource;				
				//this.uxEstadoPedidosBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxEstadoPedidosBindingSource_ListChanged);
				this.uxEstadoPedidosBindingSource.CurrentItemChanged += new System.EventHandler(OnEstadoPedidosBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnEstadoPedidosBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentEstadoPedidos = uxEstadoPedidosBindingSource.Current as Entities.EstadoPedidos;
			
			if (_currentEstadoPedidos != null)
			{
				_currentEstadoPedidos.Validate();
			}
			//_EstadoPedidos.Validate();
			OnCurrentEntityChanged();
		}

		//void uxEstadoPedidosBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.EstadoPedidos"/> instance.
		/// </summary>
		public Entities.EstadoPedidos SelectedEstadoPedidos
		{
			get {return this._currentEstadoPedidos;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxEstadoPedidosDataGridView.VirtualMode;}
			set
			{
				this.uxEstadoPedidosDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxEstadoPedidosDataGridView.AllowUserToAddRows;}
			set {this.uxEstadoPedidosDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxEstadoPedidosDataGridView.AllowUserToDeleteRows;}
			set {this.uxEstadoPedidosDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxEstadoPedidosDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxEstadoPedidosDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="EstadoPedidosDataGridViewBase"/> class.
		/// </summary>
		public EstadoPedidosDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxEstadoPedidosDataGridView = new System.Windows.Forms.DataGridView();
			this.uxEstadoPedidosBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxEstadoPedidosErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdEstadoPedidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxEstadoPedidoDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxEstadoPedidosErrorProvider
			// 
			this.uxEstadoPedidosErrorProvider.ContainerControl = this;
			this.uxEstadoPedidosErrorProvider.DataSource = this.uxEstadoPedidosBindingSource;						
			// 
			// uxEstadoPedidosDataGridView
			// 
			this.uxEstadoPedidosDataGridView.AutoGenerateColumns = false;
			this.uxEstadoPedidosDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxEstadoPedidosDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdEstadoPedidoDataGridViewColumn,
		this.uxEstadoPedidoDataGridViewColumn			});
			this.uxEstadoPedidosDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxEstadoPedidosDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxEstadoPedidosDataGridView.Name = "uxEstadoPedidosDataGridView";
			this.uxEstadoPedidosDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxEstadoPedidosDataGridView.TabIndex = 0;	
			this.uxEstadoPedidosDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxEstadoPedidosDataGridView.EnableHeadersVisualStyles = false;
			this.uxEstadoPedidosDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnEstadoPedidosDataGridViewDataError);
			this.uxEstadoPedidosDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnEstadoPedidosDataGridViewCellValueNeeded);
			this.uxEstadoPedidosDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnEstadoPedidosDataGridViewCellValuePushed);
			
			//
			// uxIdEstadoPedidoDataGridViewColumn
			//
			this.uxIdEstadoPedidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdEstadoPedidoDataGridViewColumn.DataPropertyName = "IdEstadoPedido";
			this.uxIdEstadoPedidoDataGridViewColumn.HeaderText = "IdEstadoPedido";
			this.uxIdEstadoPedidoDataGridViewColumn.Name = "uxIdEstadoPedidoDataGridViewColumn";
			this.uxIdEstadoPedidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdEstadoPedidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdEstadoPedidoDataGridViewColumn.ReadOnly = true;		
			//
			// uxEstadoPedidoDataGridViewColumn
			//
			this.uxEstadoPedidoDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxEstadoPedidoDataGridViewColumn.DataPropertyName = "EstadoPedido";
			this.uxEstadoPedidoDataGridViewColumn.HeaderText = "EstadoPedido";
			this.uxEstadoPedidoDataGridViewColumn.Name = "uxEstadoPedidoDataGridViewColumn";
			this.uxEstadoPedidoDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxEstadoPedidoDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxEstadoPedidoDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxEstadoPedidosDataGridView);
			this.Name = "EstadoPedidosDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxEstadoPedidosBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				EstadoPedidosDataGridViewEventArgs args = new EstadoPedidosDataGridViewEventArgs();
				args.EstadoPedidos = _currentEstadoPedidos;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class EstadoPedidosDataGridViewEventArgs : System.EventArgs
		{
			private Entities.EstadoPedidos	_EstadoPedidos;
	
			/// <summary>
			/// the  Entities.EstadoPedidos instance.
			/// </summary>
			public Entities.EstadoPedidos EstadoPedidos
			{
				get { return _EstadoPedidos; }
				set { _EstadoPedidos = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxEstadoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnEstadoPedidosDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxEstadoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnEstadoPedidosDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxEstadoPedidosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdEstadoPedidoDataGridViewColumn":
						e.Value = EstadoPedidosList[e.RowIndex].IdEstadoPedido;
						break;
					case "uxEstadoPedidoDataGridViewColumn":
						e.Value = EstadoPedidosList[e.RowIndex].EstadoPedido;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxEstadoPedidosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnEstadoPedidosDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxEstadoPedidosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdEstadoPedidoDataGridViewColumn":
						EstadoPedidosList[e.RowIndex].IdEstadoPedido = (System.Int32)e.Value;
						break;
					case "uxEstadoPedidoDataGridViewColumn":
						EstadoPedidosList[e.RowIndex].EstadoPedido = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
